<?php namespace Admin\Controller; 
/**
 * 图片管理
 *
 */
class PictureController extends CommonController{
		private $picture = null;
		public function __init(){
			parent::__init();
			$this->picture = new \Common\Model\Picture();
		}
		
		/**
		 * 首页
		 */
		public function index(){
				$page = Page::row(8)->make($this->picture->count());
				$picData = $this->picture->limit(Page::limit())->get();
				$this->assign('page',$page);
				$this->assign('total',$this->picture->count());
				$this->assign('picData',$picData);
				$this->display();
		}
		
		
		/**
		 * 添加数据
		 */
		public function add(){
				if (IS_POST) {
					if ($this->picture->store()) {
						$this->success('添加成功,马上为您跳转...',U('index'));
					}
					$this->error($this->picture->getError());
				}
				$theme = new \Common\Model\Theme();
				$this->assign('tdata',$theme->get());
				$this->display();
		}
		
		/**
		 * 编辑数据
		 */
		public function edit(){
				if (IS_POST) {
					if ($this->picture->edit(Q('post.pid',0,'intval'))) {
						$this->success('编辑成功,马上为您跳转...',U('index'));
					}
					$this->error($this->picture->getError());
				}
				//查出旧数据,并分配
				$lid = Q('get.pid',0,'intval');
				$theme = new \Common\Model\Theme();
				$this->assign('tdata',$theme->get());
				$this->assign('oldData',$this->picture->where(array('pid' => $lid))->find());
				$this->display();
		}
		
		//删除
		public function  del(){
			if ($this->picture->del(Q('pid',0,'intval'))) $this->success('删除成功',U('index'));
		}
}